/**
 * 
 */
package kr.co.insoft.core.repository.template.application.impl;

import java.util.List;
import java.util.Map;

import kr.co.insoft.core.mapper.template.application.ParamMapper;
import kr.co.insoft.core.model.template.application.ParamEntityModel;
import kr.co.insoft.core.repository.template.application.ParamRepository;
import kr.co.insoft.framework.exceptions.ExceptionCode;
import kr.co.insoft.framework.exceptions.RepositoryException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

/**
 * @author IN-SOFT Inc. Park Jong Taek(jtpark@in-soft.co.kr)
 * 
 */
@Repository
public class ParamRepositoryImpl implements ParamRepository {
	
	@Autowired
	ParamMapper paramMapper;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * kr.co.insoft.core.repository.template.ScriptRepository#getLists(kr.
	 * co.insoft.core.model.paging.PagingModel)
	 */
	@Override
	public List<ParamEntityModel> getList(Map<String, Object> param)
			throws RepositoryException {
		try {
			//Assert.notNull(pagingModel);
			//Assert.notNull(pagingModel.getCurrentPage());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return paramMapper.getList(param);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * kr.co.insoft.core.repository.template.ScriptRepository#getScript(
	 * kr.co.insoft.core.model.template.ParamEntityModel)
	 */

	@Override
	public ParamEntityModel getParam(
			ParamEntityModel paramEntityModel) throws RepositoryException {
		try {
			Assert.notNull(paramEntityModel);
			Assert.notNull(paramEntityModel.getParamid());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}

		try {
			return paramMapper.getParam(paramEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * kr.co.insoft.core.repository.template.script.ScriptRepository#createScript
	 * (kr.co.insoft.core.model.template.script.ParamEntityModel)
	 */
	@Override
	public ParamEntityModel createParam(
			ParamEntityModel paramEntityModel) throws RepositoryException {
		try {
			Assert.notNull(paramEntityModel);
			Assert.notNull(paramEntityModel.getParamName());
			//Assert.hasText(scriptEntityModel.getScriptName());
			Assert.notNull(paramEntityModel.getUserid());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}
		try {
			paramEntityModel.setParamid(paramMapper.getUuid());
			paramMapper.createParam(paramEntityModel);
			return paramEntityModel;
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * kr.co.insoft.core.repository.template.script.ScriptRepository#removeScript
	 * (kr.co.insoft.core.model.template.script.ParamEntityModel)
	 */
	@Override
	public void doRemoveParam(Map<String, Object> param)
			throws RepositoryException {
		try {
		//	Assert.notNull(paramEntityModel);
		//	Assert.notNull(paramEntityModel.getParamid());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}
		try {
		   paramMapper.doRemoveParam(param);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
	
	
	/* (non-Javadoc)
	 * @see kr.co.insoft.core.repository.setting.cloud.CloudRepository#isExistsCloudName(kr.co.insoft.core.model.setting.cloud.CloudEntityModel)
	 */
	@Override
	public int isExistParamName(ParamEntityModel paramEntityModel)
			throws RepositoryException {		
		try {
			Assert.notNull(paramEntityModel);
			Assert.notNull(paramEntityModel.getParamName());	
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}
		
		try {
			return paramMapper.isExistParamName(paramEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
	

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * kr.co.insoft.core.repository.template.script.ScriptRepository#doEditScript
	 * (kr.co.insoft.core.model.template.script.ParamEntityModel)
	 */
	@Override
	public void doEditParam(ParamEntityModel paramEntityModel)
			throws RepositoryException {
		try {
			Assert.notNull(paramEntityModel);
			Assert.notNull(paramEntityModel.getParamid());
		} catch (IllegalArgumentException e) {
			throw new RepositoryException(ExceptionCode.ARGUMENT_ERROR);
		}
		try {
			paramMapper.doEditParam(paramEntityModel);
		} catch (Exception e) {
			throw new RepositoryException(ExceptionCode.REPOSITORY_EXCEPTION, e);
		}
	}
}
